<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends Authenticated{
	
	function __construct() {
		parent::__construct();
		$this->load->model("user_model");
                $this->load->model("role_model");
                $this->load->model("fungsi_model");
                $this->load->model("kamar_model");
                $this->load->model("data_customer_model");
                $this->load->model("servis_model");
                $this->load->model("service_model");
	}
	
	function index(){
		$this->manajemen_kamar() ;
	}
        
        function manajemen_kamar()
        {
            $data['list_kamar']=$this->kamar_model->get_all_kamar();
            $this->load->view('header');
            $this->load->view('servis/pemesanan_kamar',$data);
            $this->load->view('footer');
        }
        
        function pengelolaan_kamar()
        {
            $data['list_kamar']=$this->kamar_model->get_all_kamar();
            $this->load->view('header');
            $this->load->view('servis/pengelolaan_kamar',$data);
            $this->load->view('footer');
        }
        
        function pesan_kamar()
        {
            $kamar_id = $_GET['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $data['tanggal'] = $_GET['tanggal'];
            $data['bulan'] = $_GET['bulan'];
//            $tanggal_masuk = ($data['bulan']+1)."/".$data['tanggal']."/".date("Y");
            $tanggal_masuk = date("Y")."-".($data['bulan']+1)."-".$data['tanggal'];
            $select = 'kamar_id';
            $clause = "(date_pesan_masuk  <= '".$tanggal_masuk."' AND date_pesan_keluar >= '".$tanggal_masuk."') ";
            $data['used'] = $this->data_customer_model->get_all_customer_clause($clause,$select);
            $data['all'] = $this->kamar_model->get_all_adjoining_by_kamar($kamar_id);
            $this->load->view('header');
            $this->load->view('servis/form_pesan_kamar',$data);
            $this->load->view('footer');
        }
        
        function checkin_kamar($cust_id)
        {
            $kamar_id = $_GET['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $data['tanggal'] = $_GET['tanggal'];
            $data['bulan'] = $_GET['bulan'];
            $tanggal_masuk = date("Y")."-".($data['bulan']+1)."-".$data['tanggal'];
            $clause = "date_pesan_masuk  <= ".$tanggal_masuk." AND date_pesan_keluar >=".$tanggal_masuk;
            $select = 'kamar_id';
            if($cust_id!=0)
            {
                $data['customer'] = $this->data_customer_model->get_customer_clause(array('id'=>$cust_id));
                $data['data_customer'] = $this->data_customer_model->get_data_customer($data['customer']['id_data_customer']);
                if($data['customer']['adjoin_to'])
                    $clause .= " AND kamar_id != ".$data['customer']['adjoin_to'];
            }
            else
                $data['customer'] = 0;
            $data['used'] = $this->data_customer_model->get_all_customer_clause($clause,$select);
            $data['all'] = $this->kamar_model->get_all_adjoining_by_kamar($kamar_id);
            $this->load->view('header');
            $this->load->view('servis/form_checkin_kamar',$data);
            $this->load->view('footer');
        }
        
        function checkout_kamar($cust_id)
        {
            $customer = $this->data_customer_model->get_customer($cust_id);
            $kamar_id = $_GET['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $data['tanggal'] = $_GET['tanggal'];
            $data['bulan'] = $_GET['bulan'];
            $data_trax['cust_id'] = $cust_id;
            if($customer['adjoin_to']>0)
                $data_trax = "cust_id = ".$cust_id." OR cust_id = ".$customer['adjoin_to'];
            $diff = abs(strtotime($customer['date_pesan_masuk']) - strtotime(date('Y-m-d')));
            $data['biaya_kamar1'] = floor($diff / (60*60*24))*$data['data_kamar']['harga']*$customer['jumlah_huni'];
            if($customer['adjoin_to']>0)
                 $data['biaya_kamar2'] = floor($diff / (60*60*24))*$data['data_kamar']['harga']*$customer['jumlah_huni'];
            $data['trax_list'] = $this->servis_model->get_trax_cust_clause($data_trax);
            $data['customer'] = $customer;
            $data['data_customer'] = $this->data_customer_model->get_data_customer($data['customer']['id_data_customer']);
            $this->load->view('header');
            $this->load->view('servis/form_checkout_kamar',$data);
            $this->load->view('footer');
        }
        
        function form_customer()
        {
            $this->load->view('header');
            $this->load->view('report/form_customer');
            $this->load->view('footer');
        }
        
        function deposit_kamar($cust_id)
        {
            $data['customer'] = $this->data_customer_model->get_customer_clause(array('id'=>$cust_id));
            $kamar_id = $data['customer']['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $data['data_customer'] = $this->data_customer_model->get_data_customer($data['customer']['id_data_customer']);
            $this->load->view('header');
            $this->load->view('servis/form_deposit_kamar',$data);
            $this->load->view('footer');
        }
        
        function transaksi_kamar($cust_id)
        {
            $data['customer'] = $this->data_customer_model->get_customer_clause(array('id'=>$cust_id));
            $kamar_id = $data['customer']['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $data['data_customer'] = $this->data_customer_model->get_data_customer($data['customer']['id_data_customer']);
            $data['list_service'] = $this->service_model->get_all_service();
            $this->load->view('header');
            $this->load->view('servis/form_transaksi_kamar',$data);
            $this->load->view('footer');
        }
        
        function cancel_kamar($cust_id)
        {
            $kamar_id = $_GET['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $clause['customer.id'] = $cust_id;
            $data['data_customer'] = $this->data_customer_model->get_customer_join_data_clause($clause);
            $customer = $this->data_customer_model->get_customer($cust_id);
            if($customer['adjoin_to']>0)
            {
                $clause['customer.id'] = $customer['adjoin_to'];
                $data['data_customer2'] = $this->data_customer_model->get_customer_join_data_clause($clause);
            }
            $clause = array();
            $clause['waiting_to'] = $cust_id;
            $clause['status_pesan'] = "waiting list";
            $data['list_customer'] = $this->data_customer_model->get_customer_join_data_clause($clause);
            if($customer['adjoin_to']>0)
            {
                $clause['waiting_to'] = $customer['adjoin_to'];
                $clause['status_pesan'] = "waiting list";
                $data['list_customer2'] = $this->data_customer_model->get_customer_join_data_clause($clause);
            }
            $this->load->view('header');
            $this->load->view('servis/form_cancel_kamar',$data);
            $this->load->view('footer');
        }
        
        function waitinglist_kamar($cust_id)
        {
            $kamar_id = $_GET['kamar_id'];
            $data['data_kamar']=$this->kamar_model->get_kamar_join_kategori($kamar_id);
            $data['customer_id'] = $cust_id;
//                $data['customer'] = $this->data_customer_model->get_customer_clause(array('id'=>$cust_id));
//                $data['data_customer'] = $this->data_customer_model->get_data_customer($data['customer']['id_data_customer']);
            
            $data['customer'] = 0;
            $data['tanggal'] = $_GET['tanggal'];
            $data['bulan'] = $_GET['bulan'];
//            $tanggal_masuk = ($data['bulan']+1)."/".$data['tanggal']."/".date("Y");
            $tanggal_masuk = date("Y")."-".($data['bulan']+1)."-".$data['tanggal'];
            $select = 'kamar_id';
            $clause = "(date_pesan_masuk  <= '".$tanggal_masuk."' AND date_pesan_keluar >= '".$tanggal_masuk."') ";
            $data['used'] = $this->data_customer_model->get_all_customer_clause($clause,$select);
            $data['all'] = $this->kamar_model->get_all_adjoining_by_kamar($kamar_id);
            
            
            $this->load->view('header');
            $this->load->view('servis/form_waitinglist_kamar',$data);
            $this->load->view('footer');
        }
        
        function pesan_kamar_process()
        {
//            print_r($_GET);
//            die();
            $data_customer['no_pengenal'] = $_GET['no_pengenal'];
            $data_customer['jenis_pengenal'] = $_GET['jenis_pengenal'];
            $data_customer['country_of_passport'] = $_GET['country_of_passport'];
            $data_customer['first_name'] = $_GET['first_name'];
            $data_customer['last_name'] = $_GET['last_name'];
            if($_GET['status_data_customer']=='-')
                $data_customer_id = $this->data_customer_model->add_data_customer($data_customer);
            else
            {
                $data_customer['id'] = $_GET['status_data_customer'];
                $data_customer_id = $this->data_customer_model->update_data_customer($data_customer);
            }
            $pesan_kamar['kamar_id'] = $_GET['id_kamar'];
            $date_temp = explode("/", $_GET['date_pesan_masuk']);
            $pesan_kamar['date_pesan_masuk'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $date_temp = explode("/", $_GET['date_pesan_keluar']);
            $pesan_kamar['date_pesan_keluar'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $pesan_kamar['id_data_customer'] = $data_customer_id;
            $pesan_kamar['jumlah_huni'] = $_GET['jumlah_huni'];
            $pesan_kamar['waktu_pesan'] = date("Y-m-d H:i:s");
            $pesan_kamar['status_pesan'] = "pesan";
            $customer_id = $this->data_customer_model->add_customer($pesan_kamar);
            if(isset($_GET['adjoining']) && $_GET['adjoining']!='-')
            {
                $pesan_kamar['adjoin_to'] = $customer_id;
                $pesan_kamar['kamar_id'] = $_GET['adjoining'];
                $customer_id_adjoin = $this->data_customer_model->add_customer($pesan_kamar);
                $update_kamar['id'] = $customer_id;
                $update_kamar['adjoin_to'] = $customer_id_adjoin;
                $this->data_customer_model->update_customer($update_kamar);
            }
            if($_GET['harga_trax']!='')
            {
                $deposit['harga_trax'] = $_GET['harga_trax'];
                $deposit['jenis_trax'] = "deposit";
                $deposit['keterangan'] = $_GET['keterangan'];
                $deposit['pembayaran_trax'] = $_GET['pembayaran_trax'];
                $deposit['cust_id'] = $customer_id;
                $deposit['fo_id'] = $this->session->userdata('user');
                $deposit['waktu_trax'] = $pesan_kamar['waktu_pesan'];
                $deposit['nama_trax'] = 'pembayaran awal pesan';
                $this->servis_model->add_trax_cust($deposit);
            }
            redirect(HOME."manajemen_kamar");
        }
        
        function checkin_kamar_process()
        {
//            print_r($_GET);
//            die();
            $data_customer['no_pengenal'] = $_GET['no_pengenal'];
            $data_customer['jenis_pengenal'] = $_GET['jenis_pengenal'];
            $data_customer['country_of_passport'] = $_GET['country_of_passport'];
            $data_customer['first_name'] = $_GET['first_name'];
            $data_customer['last_name'] = $_GET['last_name'];
            if($_GET['id_data_customer']==0)
                $data_customer_id = $this->data_customer_model->add_data_customer($data_customer);
            else
            {
                $data_customer['id'] = $_GET['id_data_customer'];
                $data_customer_id = $this->data_customer_model->update_data_customer($data_customer);
            }
            $pesan_kamar['kamar_id'] = $_GET['id_kamar'];
            $date_temp = explode("/", $_GET['date_pesan_masuk']);
            $pesan_kamar['date_pesan_masuk'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $date_temp = explode("/", $_GET['date_pesan_keluar']);
            $pesan_kamar['date_pesan_keluar'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $pesan_kamar['id_data_customer'] = $data_customer_id;
            $pesan_kamar['jumlah_huni'] = $_GET['jumlah_huni'];
            $pesan_kamar['waktu_checkin'] = date("Y-m-d H:i:s");
            if($_GET['id_customer']==0)
            {
                $pesan_kamar['waktu_pesan'] = date("Y-m-d H:i:s");
                $pesan_kamar['status_pesan'] = "pesan";
                $customer_id = $this->data_customer_model->add_customer($pesan_kamar);
            }
            else
            {
                $pesan_kamar['id'] = $_GET['id_customer'];
                $customer_id = $this->data_customer_model->update_customer($pesan_kamar);
                if($customer_id)
                {
                    $clause_delete['waiting_to'] = $customer_id;
                    $this->data_customer_model->delete_customer_clause($clause_delete);
                }
            }
            if(isset($_GET['adjoining']))
            {
                if(($_GET['adjoining'] || $_GET['adjoining']!='-') && !($_GET['adjoin_status']>0))
                {
                    if(isset($pesan_kamar['id']))
                        unset($pesan_kamar['id']);
                    $pesan_kamar['adjoin_to'] = $customer_id;
                    $pesan_kamar['kamar_id'] = $_GET['adjoining'];
                    $customer_id_adjoin = $this->data_customer_model->add_customer($pesan_kamar);
                    $update_kamar['id'] = $customer_id;
                    $update_kamar['adjoin_to'] = $customer_id_adjoin;
                    $this->data_customer_model->update_customer($update_kamar);
                }
                else if(($_GET['adjoining'] || $_GET['adjoining']!='-') && $_GET['adjoin_status']>0)
                {
                    $customer_id_adjoin = $_GET['adjoin_status'];
                    $update_kamar['id'] = $customer_id;
                    $update_kamar['adjoin_to'] = $customer_id_adjoin;
                    $this->data_customer_model->update_customer($update_kamar);
                    $pesan_kamar['kamar_id'] = $_GET['adjoining'];
                    $pesan_kamar['adjoin_to'] = $customer_id;
                    $pesan_kamar['id'] = $customer_id_adjoin;
                    $this->data_customer_model->update_customer($pesan_kamar);
                    if($customer_id)
                    {
                        $clause_delete['waiting_to'] = $customer_id_adjoin;
                        $this->data_customer_model->delete_customer_clause($clause_delete);
                    }
                }
                else if($_GET['adjoining']=='-' && $_GET['adjoin_status']>0)
                {
                    die('3');
                    $update_kamar['id'] = $customer_id;
                    $update_kamar['adjoin_to'] = '';
                    $this->data_customer_model->update_customer($update_kamar);
                    $delete_adjoin = $this->data_customer_model->get_customer($customer_id);
                    $this->data_customer_model->delete_customer($delete_adjoin['adjoin_to']);
                }
            }
            if($_GET['harga_trax']!='')
            {
                $deposit['harga_trax'] = $_GET['harga_trax'];
                $deposit['jenis_trax'] = "deposit";
                $deposit['keterangan'] = $_GET['keterangan'];
                $deposit['pembayaran_trax'] = $_GET['pembayaran_trax'];
                $deposit['cust_id'] = $customer_id;
                $deposit['fo_id'] = $this->session->userdata('user');
                $deposit['waktu_trax'] = $pesan_kamar['waktu_checkin'];
                $deposit['nama_trax'] = 'pembayaran awal check in';
                $this->servis_model->add_trax_cust($deposit);
            }
            redirect(HOME."manajemen_kamar");
        }
        
        function waitinglist_kamar_process()
        {
//            print_r($_GET);
//            die();
            $data_customer['no_pengenal'] = $_GET['no_pengenal'];
            $data_customer['jenis_pengenal'] = $_GET['jenis_pengenal'];
            $data_customer['country_of_passport'] = $_GET['country_of_passport'];
            $data_customer['first_name'] = $_GET['first_name'];
            $data_customer['last_name'] = $_GET['last_name'];
            if($_GET['id_data_customer']==0)
                $data_customer_id = $this->data_customer_model->add_data_customer($data_customer);
            else
            {
                $data_customer['id'] = $_GET['id_data_customer'];
                $data_customer_id = $this->data_customer_model->update_data_customer($data_customer);
            }
            $pesan_kamar['kamar_id'] = $_GET['id_kamar'];
            $date_temp = explode("/", $_GET['date_pesan_masuk']);
            $pesan_kamar['date_pesan_masuk'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $date_temp = explode("/", $_GET['date_pesan_keluar']);
            $pesan_kamar['date_pesan_keluar'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $pesan_kamar['id_data_customer'] = $data_customer_id;
            $pesan_kamar['jumlah_huni'] = $_GET['jumlah_huni'];
            $pesan_kamar['waiting_to'] = $_GET['id_waitinglist_to'];
            if($_GET['id_customer']==0)
            {
                $pesan_kamar['waktu_pesan'] = date("Y-m-d H:i:s");
                $pesan_kamar['status_pesan'] = "waiting list";
                $customer_id = $this->data_customer_model->add_customer($pesan_kamar);
            }
            else
            {
                $pesan_kamar['id'] = $_GET['id_customer'];
                $customer_id = $this->data_customer_model->update_customer($pesan_kamar);
            }
            if(isset($_GET['adjoining']) && $_GET['adjoining']!='-')
            {
                $pesan_kamar['adjoin_to'] = $customer_id;
                $pesan_kamar['kamar_id'] = $_GET['adjoining'];
                $pesan_kamar['waiting_to'] = $_GET['id_waitinglist_to'];
                $customer_id_adjoin = $this->data_customer_model->add_customer($pesan_kamar);
                $update_kamar['id'] = $customer_id;
                $update_kamar['adjoin_to'] = $customer_id_adjoin;
                $this->data_customer_model->update_customer($update_kamar);
            }
            if($_GET['harga_trax']!='')
            {
                $deposit['harga_trax'] = $_GET['harga_trax'];
                $deposit['jenis_trax'] = "deposit";
                $deposit['keterangan'] = $_GET['keterangan'];
                $deposit['pembayaran_trax'] = $_GET['pembayaran_trax'];
                $deposit['cust_id'] = $customer_id;
                $deposit['fo_id'] = $this->session->userdata('user');
                $deposit['waktu_trax'] = $pesan_kamar['waktu_checkin'];
                $deposit['nama_trax'] = 'pembayaran awal pesan';
                $this->servis_model->add_trax_cust($deposit);
            }
            redirect(HOME."manajemen_kamar");
        }
        
        function checkout_kamar_process()
        {
//            print_r($_GET);
//            die();
            $data_customer['no_pengenal'] = $_GET['no_pengenal'];
            $data_customer['jenis_pengenal'] = $_GET['jenis_pengenal'];
            $data_customer['country_of_passport'] = $_GET['country_of_passport'];
            $data_customer['first_name'] = $_GET['first_name'];
            $data_customer['last_name'] = $_GET['last_name'];
            $data_customer['id'] = $_GET['id_data_customer'];
            $data_customer_id = $this->data_customer_model->update_data_customer($data_customer);
            $pesan_kamar['kamar_id'] = $_GET['id_kamar'];
            $date_temp = explode("/", $_GET['date_pesan_masuk']);
            $pesan_kamar['date_pesan_masuk'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $date_temp = explode("/", $_GET['date_pesan_keluar']);
            $pesan_kamar['date_pesan_keluar'] = date($date_temp[2]."-".$date_temp[0]."-".$date_temp[1]);
            $pesan_kamar['id_data_customer'] = $data_customer_id;
            $pesan_kamar['jumlah_huni'] = $_GET['jumlah_huni'];
            $pesan_kamar['waktu_checkout'] = date("Y-m-d H:i:s");
            $pesan_kamar['id'] = $_GET['id_customer'];
            $customer_id = $this->data_customer_model->update_customer($pesan_kamar);
            if($_GET['adjoin_status']>0)
            {
                $pesan_kamar['id'] = $_GET['adjoin_status'];
                $this->data_customer_model->update_customer($pesan_kamar);
            }
            if($_GET['harga_trax']!='')
            {
                $deposit['harga_trax'] = $_GET['harga_trax'];
                $deposit['jenis_trax'] = "deposit";
                $deposit['keterangan'] = $_GET['keterangan'];
                $deposit['pembayaran_trax'] = $_GET['pembayaran_trax'];
                $deposit['cust_id'] = $customer_id;
                $deposit['fo_id'] = $this->session->userdata('user');
                $deposit['waktu_trax'] = $pesan_kamar['waktu_checkout'];
                $deposit['nama_trax'] = 'pembayaran awal pesan';
                $this->servis_model->add_trax_cust($deposit);
            }
            redirect(HOME."manajemen_kamar");
        }
        
        function deposit_kamar_process()
        {
//            print_r($_GET);
//            die();
            
            $waktu_curr = date("Y-m-d H:i:s");
            $customer_id  = $_GET['id_customer'];
           
            if($_GET['harga_trax']!='')
            {
                $deposit['harga_trax'] = $_GET['harga_trax'];
                $deposit['jenis_trax'] = "deposit";
                $deposit['keterangan'] = $_GET['keterangan'];
                $deposit['pembayaran_trax'] = $_GET['pembayaran_trax'];
                $deposit['cust_id'] = $customer_id;
                $deposit['fo_id'] = $this->session->userdata('user');
                $deposit['waktu_trax'] = $waktu_curr;
                $deposit['nama_trax'] = 'pembayaran awal pesan';
                $this->servis_model->add_trax_cust($deposit);
            }
            redirect(HOME."manajemen_kamar");
        }
        
        function cancel_kamar_process()
        {
//            print_r($_GET);
//            die();
            
            $id_cust_cancel = $_GET['id_cust_cancel'];
            
            $this->data_customer_model->delete_customer($id_cust_cancel);
            if(isset($_GET['id_cust_cancel2']))
                $this->data_customer_model->delete_customer($_GET['id_cust_cancel2']);
            if(isset($_GET['id_cust']))
            {
                $id_cust = $_GET['id_cust'];
                $data['status_pesan'] = 'pesan';
                $data['id'] = $id_cust;
                $this->data_customer_model->update_customer($data);
            }
            if(isset($_GET['id_cust2']))
            {
                $id_cust = $_GET['id_cust2'];
                $data['status_pesan'] = 'pesan';
                $data['id'] = $id_cust;
                $this->data_customer_model->update_customer($data);
            }
            redirect(HOME."manajemen_kamar");
        }
         function transaksi_kamar_process()
        {
//            print_r($_GET);
//            die();
            
            $waktu_curr = date("Y-m-d H:i:s");
            $customer_id  = $_GET['id_customer'];
           
            if($_GET['harga_trax']!='')
            {
                $deposit['harga_trax'] = $_GET['harga_trax'];
                $deposit['jenis_trax'] = "pengeluaran";
                $deposit['keterangan'] = $_GET['keterangan'];
                $deposit['cust_id'] = $customer_id;
                $deposit['fo_id'] = $this->session->userdata('user');
                $deposit['waktu_trax'] = $waktu_curr;
                $deposit['nama_trax'] = $_GET['nama_trax'];
                $this->servis_model->add_trax_cust($deposit);
            }
            $deposit=array();
            if(isset($_GET['id_service']) && count($_GET['id_service'])>0)
            {
                $deposit['jenis_trax'] = "pengeluaran";
                for($i=0;$i<count($_GET['id_service']);$i++)
                {
                    $temp = $this->service_model->get_service($_GET['id_service'][$i]);
                    $deposit['harga_trax'] = $temp['harga'];
                    $deposit['keterangan'] = $temp['keterangan'];
                    $deposit['cust_id'] = $customer_id;
                    $deposit['fo_id'] = $this->session->userdata('user');
                    $deposit['waktu_trax'] = $waktu_curr;
                    $deposit['nama_trax'] = $temp['nama_servis'];
                    $this->servis_model->add_trax_cust($deposit);
                }
            }
            
            redirect(HOME."manajemen_kamar");
        }
        

        function list_user()
        {
            $data['list_user']=$this->user_model->get_all_user_join_role();
            $this->load->view('header');
            $this->load->view('user/list_user',$data);
            $this->load->view('footer');
        }
        
        function add_user()
        {
            $data['role']=$this->role_model->get_all_role();
            $this->load->view('header');
            $this->load->view('user/add_user',$data);
            $this->load->view('footer');
        }
        
        function add_user_process()
        {
            $data['password'] = $this->input->post('password');
            $data['user'] = $this->input->post('user');
            $data['role_id'] = $this->input->post('role_id');
            $this->user_model->new_user($data);
            redirect(HOME);
        }
        
        function edit_user($id)
        {
            $data = $this->user_model->get_user($id);
            $data['role']=$this->role_model->get_all_role();
            $this->load->view('header');
            $this->load->view('user/form_edit_user',$data);
            $this->load->view('footer');
        }
        
        function edit_user_process()
        {
            $data['password'] = $this->input->post('password');
            $data['user'] = $this->input->post('user');
            $data['role_id'] = $this->input->post('role_id');
            $data['id'] = $this->input->post('id');
            $this->user_model->update_user($data);
            redirect(HOME);
        }
        
        function delete_user($id)
        {
            $this->user_model->delete_user($id);
            redirect(HOME);
        }
        
        function logout(){
		$this->session->unset_userdata('user');
		$this->session->unset_userdata('role_id');
                redirect(HOME);
	}
	
}
/** End of file */
